package org.springblade.weixin.controller;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.weixin.feign.IWeixinClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@NonDS
@RestController
@AllArgsConstructor
@RequestMapping("miniapp/test")
@Api(value = "微信小程序测试接口", tags = "小程序接口")
public class MiniappTestController {

	private final IWeixinClient weixinClient;

	@SneakyThrows
	@GetMapping("/code2-session")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "获取code2-session", notes = "微信小程序登录")
	R<WxMaJscode2SessionResult> getUserPhoneNumber(@ApiParam(value = "code",required = true) @RequestParam("code") String code) {
		WxMaJscode2SessionResult code2Session = weixinClient.getCode2Session(code);
		return R.data(code2Session);
	}

}
